#include "hplcqinfinecollectorprotocol.h"
#include "hplcqinfinecollectorsendpacket.h"
#include "hplcqinfinecollectorparsepacket.h"
#include "hplcqinfinecollectorprotocoldata.h"
#include "hplcqinfinecollectorparsesystempacket.h"
#include "hplcqinfinecollectorsendsystempacket.h"
#include "common/hplcqinfinemakepacket.h"
#include "common/hplcqinfinefindpacket.h"

namespace hplc
{
namespace qinfine
{

HplcQinfineCollectorProtocol::HplcQinfineCollectorProtocol(CollectorParam &param, QObject *parent)
    : HplcQinfineCollectorProtocol (*new HplcQinfineCollectorProtocolData(), param, parent)
{

}

HplcQinfineCollectorProtocol::HplcQinfineCollectorProtocol(HplcQinfineCollectorProtocolData &data, CollectorParam &param, QObject *parent)
    : HplcQinfineProtocolCommon (data, param, parent)
    , m_param(&param)
{
    HplcQinfineCollectorParsePacket *parser = new HplcQinfineCollectorParsePacket(data, param, this);
    HplcQinfineCollectorSendPacket *sender = new HplcQinfineCollectorSendPacket (data, this);
    connect(sender, &HplcQinfineSendCommonPacket::requestSend, this, &HplcQinfineProtocolCommon::requestSend);

    HplcQinfineCollectorParseSystemPacket *systemParser = new HplcQinfineCollectorParseSystemPacket(data, param, this);
    HplcQinfineCollectorSendSystemPacket *systemSender = new HplcQinfineCollectorSendSystemPacket(data);

    data.m_parser = parser;
    data.m_sender = sender;
    data.m_systemParser = systemParser;
    data.m_systemSender = systemSender;
}

HplcQinfineCollectorProtocol::~HplcQinfineCollectorProtocol()
{
    HplcQinfineCollectorProtocolData *d = static_cast<HplcQinfineCollectorProtocolData*>(m_d);
    delete d->m_sender;
    delete d->m_parser;
    delete d->m_systemParser;
    delete d->m_systemSender;
}

bool HplcQinfineCollectorProtocol::setProtocolCmd(int id, QVariant &var)
{
    return HplcQinfineProtocolCommon::setProtocolCmd(id, var);
}

bool HplcQinfineCollectorProtocol::getProtocolCmd(int id, QVariant &var)
{
    return HplcQinfineProtocolCommon::getProtocolCmd(id, var);
}

HplcQinfineCollectorSendPacket *HplcQinfineCollectorProtocol::getCollectorSender()
{
    return static_cast<HplcQinfineCollectorSendPacket*>(m_d->m_sender);
}

HplcQinfineCollectorSendSystemPacket *HplcQinfineCollectorProtocol::getCollectorSystemSender()
{
    HplcQinfineCollectorProtocolData *m_d = static_cast<HplcQinfineCollectorProtocolData*>(this->m_d);
    return m_d->m_systemSender;
}

void HplcQinfineCollectorProtocol::setModel(quint8 model)
{
//    m_param->
}

} // qinfine
} // hplc
